import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get_connect/http/src/utils/utils.dart';

import '../../../lib_basemodel/chat_room/flyScreen/flying_data.dart';
import '../../../lib_runtime/utils/string_util.dart';
import '../../theme/jr.dart';
import '../../../resource/language/generated/l10n.dart';
import '../../utils/constant/text_styles.dart';
import '../../utils/screen_utils.dart';
import 'gift_floating_content_builder.dart';

class BoxOpenBuilder extends GiftFloatingContentBuilder {
  @override
  Widget build(BuildContext context, FlyingData data) {
    return GestureDetector(
      onTap: () {
        // if (data.hasChannel() && data.channel > 0) {
        //   RoomPage.show(
        //       rootNavigatorState.currentContext!, data.channel.toInt());
        // } else {
        //   PersonalHomePage.show(
        //       rootNavigatorState.currentContext!, data.trigger.id.toInt(),
        //       refer: 'box_flying');
        // }
      },
      child: IntrinsicHeight(
        child: Stack(
          alignment: Alignment.topCenter,
          children: [
            if (data.giftUrl != null)
              JR.img(data.giftUrl!,
                  fit: BoxFit.fitWidth, width: ScreenUtils.ins.screenWidth),
            Padding(
              padding: EdgeInsets.only(top: 34.h),
              child: Row(
                mainAxisSize: MainAxisSize.max,
                children: [
                  SizedBox(width: 29.w),
                  JR.img(StringUtil.formatImgUrl(data.giftUrl),
                      width: 60.w, height: 60.w, fit: BoxFit.contain),
                  Expanded(
                      child: Column(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      buildUserInfo(data),
                      Text('T.current.extract_lucky_gift',
                          style: JRTextStyles.styleFont12W600
                              .copyWith(color: Colors.white))
                    ],
                  )),
                  // if (data.hasChannel() && data.channel > 0)
                  Container(
                    width: 28.w,
                    height: 28.w,
                    alignment: Alignment.center,
                    decoration: const BoxDecoration(
                        shape: BoxShape.circle, color: Colors.white10),
                    child: Icon(Icons.home_rounded,
                        size: 24.w, color: Colors.white),
                  ),
                  SizedBox(width: 28.w),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  @override
  bool match(FlyingData data) {
    // return data.hasBoxItem() && data.boxItem.id > 0;
    return data.giftUrl != null;
  }
}
